﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;

namespace ClientSide
{
    
  public partial class MainPage : PhoneApplicationPage
  {
    int a;
    // Constructor
    public MainPage()
    {
      InitializeComponent();
      DataContext = User.Load();
    }

    private void Login_Click(object sender, RoutedEventArgs e)
    {
        var user = (User)DataContext;
        if (user.RememberMe)
        {
            user.Save();
        }
        NavigationService.Navigate(new Uri("/Calc.xaml", UriKind.Relative));
    }
  }

  public class User 
  {
      private string _username;

      public string Username
      {
          get { return _username; }
          set { _username = value; }
      }

      private string _password;

      public string Password
      {
          get { return _password; }
          set { _password = value; }
      }

      private bool _RememberMe;

      public bool RememberMe
      {
          get { return _RememberMe; }
          set { _RememberMe = value; }
      }

      public static User Load()
      {
          string id = "credentials";
          var isolated = IsolatedStorageSettings.ApplicationSettings;
          if (isolated.Contains(id))
          {
              return (User)isolated[id];
          }
          else
          {
              return new User();
          }
      }

      public void Save()
      {
          string id = "credentials";
          var isolated = IsolatedStorageSettings.ApplicationSettings;
          if (isolated.Contains(id))
          {
              isolated[id] = this;
          }
          else
          {
              isolated.Add(id, this);
          }
      }

  }
}